package com.yiyi.credit.manage.sso.manager.controller;


import com.yiyi.credit.manage.sso.common.exception.ResponseCode;
import com.yiyi.credit.manage.sso.model.dto.SysResourceDto;
import com.yiyi.credit.manage.sso.model.dto.response.Response;
import com.yiyi.credit.manage.sso.model.entity.SysRoleResource;
import com.yiyi.credit.manage.sso.service.inner.SysRoleResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
public class SysRoleResourceController {

    //private static Logger logger = LoggerFactory.getLogger(SysRoleResourceController.class);

    @Autowired
    SysRoleResourceService sysRoleResourceService;


    @RequestMapping(value = "/getSysRoleResourceTreeList")
    public Object getSysRoleResourceTreeList(@RequestParam Long sysInfoId, @RequestParam Long roleId) throws Exception {

        List<SysResourceDto> sysRoleResourceList = sysRoleResourceService.getSysRoleResourceTree(sysInfoId, roleId);
        return new Response<>(sysRoleResourceList);
    }


    @RequestMapping(value = "/getSysRoleColumnsTreeList")
    public Object getSysRoleColumnsTreeList(@RequestParam Long sysInfoId, @RequestParam Long roleId) throws Exception {

        List<Map<String, Object>> sysRoleColumnsList = sysRoleResourceService.getSysRoleColumnsTree(sysInfoId, roleId);
        return new Response<>(sysRoleColumnsList);
    }


    @RequestMapping(value = "/assignSysRoleResource")
    public Object assignSysRoleResource(@RequestParam Long sysInfoId, @RequestParam Long roleId,
                                        @RequestParam String ids) throws Exception {

        sysRoleResourceService.assignSysRoleResource(sysInfoId, roleId, ids);
        return new Response<>();
    }


    @RequestMapping(value = "/assignSysRoleColumns")
    public Object assignSysRoleColumns(@RequestBody SysRoleResource sysRoleResource) throws Exception {
        if (null == sysRoleResource.getId()) {
            new Response<>(ResponseCode.PARAM_NOT_PASS);
        }
        sysRoleResourceService.updateSysRoleResource(sysRoleResource);
        return new Response<>();
    }

}
